//
//  OrdersInfoTableViewCell.swift
//  DiDiRecycle
//
//  Created by abb on 16/8/8.
//  Copyright © 2016年 abb. All rights reserved.
//

import UIKit

class OrdersInfoTableViewCell: UITableViewCell {
    
    var key:String? {
        didSet{
            keyLabel.text = key! + ": "
            
        }
    }
    
    var value:String? {
        didSet {
            valueLabel.text = value
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupUI()
    }
    
    private func setupUI() {
        addSubview(keyLabel)
        addSubview(valueLabel)
        keyLabel.snp_makeConstraints { (make) in

            make.left.equalTo(self).offset(20)
            make.width.equalTo(self).multipliedBy(0.2)
            make.top.equalTo(self).offset(5)
        }
        valueLabel.snp_makeConstraints { (make) in
            make.top.equalTo(keyLabel)
            make.left.equalTo(keyLabel.snp_right)
            make.right.equalTo(self).offset(-20)

        }
    }
    
    func rowHeight(value:String) ->CGFloat{
        
        // 为了能够调用didSet,计算配图的高度
        self.value = value
        
        // 2.强制更新界面
        self.layoutIfNeeded()
        
        // 3.返回底部视图最大Y值
        return CGRectGetMaxY(valueLabel.frame)
    }
    
    
    private lazy var keyLabel:UILabel = UILabel.creatLabel(color: UIColor.blackColor(), fontSize: 14)
    
    private lazy var valueLabel:UILabel = {
        let label = UILabel.creatLabel(color: UIColor.blackColor(), fontSize: 14)
        label.numberOfLines = 2
        return label
    }()
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

}
